<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="renderer" content="webkit">

    <title>${setting.siteName} - 主页</title>
    <meta name="keywords" content="${setting.siteName}">
    <meta name="description" content="${setting.siteName}">

    <!-- BEGIN HEADER -->
    [#include "/admin/include/style.ftl"]
    <!-- END HEADER -->
</head>

<body class="gray-bg">
<div class="wrapper wrapper-content  animated fadeInRight">

    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <form id="listForm" action="list.jhtml" method="get">
                    <div class="ibox-title">
                        <h5>管理员列表 </h5>
                        <div class="ibox-tools">
                            <a class="btn btn-outline btn-success btn-xs" id="btn-add-loippi" href="add.jhtml"><i
                                        class="fa fa-plus"></i> 新增</a>
                            <a class="btn btn-outline btn-danger btn-xs btn-delete-loippi-group"><i
                                        class="fa fa-trash"></i> 删除</a>
                            <a class="btn btn-outline btn-info btn-xs btn-open-loippi-group"><i
                                        class="fa fa-unlock-alt"></i> 启用</a>
                            <a class="btn btn-outline btn-warning btn-xs btn-close-loippi-group"><i
                                        class="fa fa-lock"></i> 禁用</a>
                        </div>
                    </div>
                    <div class="ibox-content">
                        <div class="dataTables_wrapper form-inline">
                            <table class="table table-striped table-bordered table-hover dataTables-example dataTable">
                                <thead>
                                <tr>

                                    <th><input type="checkbox" class="i-checks" name="checkAll"></th>
                                    <th>昵称</th>
                                    <th>用户名</th>
                                    <th>角色</th>
                                    <th>创建日期</th>
                                    <th>最近登录</th>
                                    <th>状态</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                [#list page.content as user]
                                    <tr>
                                        <td>
                                            <input type="checkbox" class="i-checks" name="ids" value="${user.id}">
                                        </td>
                                        <td>${user.nickname}</td>
                                        <td>${user.username}</td>
                                        <td>${user.role.name}</td>
                                        <td>${(user.createDate?string('yyyy-MM-dd HH:mm:ss'))!''}</td>
                                        <td>${(user.loginDate?string('yyyy-MM-dd HH:mm:ss'))!''}</td>
                                        [#if user.isEnabled == true]
                                            <td>正常</td>
                                        [#else]
                                            <td>禁用</td>
                                        [/#if]
                                        <td>
                                            <a class="btn btn-info btn-xs btn-edit-loippi" data-id="${user.id}"
                                               href="edit.jhtml?id=${user.id}"><i class="fa fa-paste"></i> 编辑</a>
                                            <a class="btn btn-danger btn-xs btn-delete-loippi" data-id="${user.id}"><i
                                                        class="fa fa-trash"></i> 删除</a>
                                            <!-- 用户正常的时候显示禁用，禁用的时候显示正常 -->
                                            [#if user.isEnabled == false]
                                                <a class="btn btn-info btn-xs btn-open-loippi" data-id="${user.id}"><i
                                                            class="fa fa-unlock-alt"></i>启用</a>
                                            [#else]
                                                <a class="btn btn-warning btn-xs btn-close-loippi" data-id="${user.id}"><i
                                                            class="fa fa-lock"></i>禁用</a>
                                            [/#if]
                                        </td>
                                    </tr>
                                [/#list]
                                </tbody>
                            </table>
                            [@pagination pageNumber = page.pageNumber totalPages = page.totalPages]
                                [#include "/admin/include/pagination.ftl"]
                            [/@pagination]
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

<!-- BEGIN Script -->
[#include "/admin/include/script.ftl"]
<!-- END Script -->
<script>
    $(document).ready(function () {
        [@flash_message /]
        //开启用户
        $(".btn-open-loippi").click(function () {
            var $this = $(this);
            bootbox.confirm(message("确定要开启吗？"), function (result) {
                if (result) {
                    $.ajax({
                        url: "open.jhtml",
                        type: "POST",
                        data: {ids: $this.attr('data-id')},
                        dataType: "json",
                        cache: false,
                        success: function (message) {
                            /* window.setTimeout(function() {
                                window.location.reload();
                            }, 500); */
                            art.message(message);
                            if (message.type == "success") {
                                window.setTimeout(function () {
                                    window.location.reload();
                                }, 1000);
                            }
                        }
                    });
                }
            });
        });

        //禁用用户
        $(".btn-close-loippi").click(function () {
            var $this = $(this);
            bootbox.confirm(message("确定要禁用吗？"), function (result) {
                if (result) {
                    $.ajax({
                        url: "close.jhtml",
                        type: "POST",
                        data: {ids: $this.attr('data-id')},
                        dataType: "json",
                        cache: false,
                        success: function (message) {
                            /* window.setTimeout(function() {
                                window.location.reload();
                            }, 500); */
                            art.message(message);
                            if (message.type == "success") {
                                window.setTimeout(function () {
                                    window.location.reload();
                                }, 1000);
                            }
                        }
                    });
                }
            });
        });


        // 启用多条记录
        $(".btn-open-loippi-group").click(function () {
            var $checkeds = jQuery($("input[name='ids']:checked"));

            if ($checkeds.length == 0) {
                art.warn('请选择启用记录！');
                return;
            }

            bootbox.confirm(message("确定启用吗？"), function (result) {
                if (result) {
                    $.ajax({
                        url: "open.jhtml",
                        type: "POST",
                        data: $checkeds.serialize(),
                        dataType: "json",
                        cache: false,
                        success: function (message) {
                            art.message(message);
                            if (message.type == "success") {
                                window.setTimeout(function () {
                                    window.location.reload();
                                }, 1000);
                            }
                        }
                    });
                }
            });
        });

        // 禁用多条记录
        $(".btn-close-loippi-group").click(function () {
            var $checkeds = jQuery($("input[name='ids']:checked"));

            if ($checkeds.length == 0) {
                art.warn('请选择禁用记录！');
                return;
            }

            bootbox.confirm(message("确定禁用用户吗？"), function (result) {
                if (result) {
                    $.ajax({
                        url: "close.jhtml",
                        type: "POST",
                        data: $checkeds.serialize(),
                        dataType: "json",
                        cache: false,
                        success: function (message) {
                            art.message(message);
                            if (message.type == "success") {
                                window.setTimeout(function () {
                                    window.location.reload();
                                }, 1000);
                            }
                        }
                    });
                }
            });
        });
    });
</script>
</body>

</html>
